package com.kfm.jdbc.day01;

import java.sql.*;

public class Demo07 {

    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/scott";
        String user = "root";
        String pass = "root";

        /*
               1. 注册驱动
               2. 创建连接
               3. 创建 PreparedStatement 对象
               4. 设置参数
               5. 执行操作
               6. 解析结果
               7. 释放资源
         */

        String sql = "select * from emp";
        try(
            // 创建连接
            Connection conn = DriverManager.getConnection(url, user, pass);
            // 创建 PreparedStatement 对象
            PreparedStatement preparedStatement = conn.prepareStatement(sql)
        ) {
            // 设置参数

            // 执行操作
            ResultSet resultSet = preparedStatement.executeQuery();

            while (resultSet.next()){
                System.out.print(resultSet.getRow() + " - ");
                // 获取列
//                resultSet.getObject("empno");
                Object object = resultSet.getObject(1);
                Object object1 = resultSet.getObject(2);
                System.out.println(object + " - " + object1);
            }

            resultSet.close();

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
